var express = require('express');
var router = express.Router();
let qn = require('../config/qiniu');  //导入七牛文件   上方组件文件我命名qiniu.js
//结果包装函数
let result = function (obj, bool, status) {
    if (bool) {
        return { status: 200, data: obj };
    } else {
        return { status: status, data: obj };
    }
}

/* GET users listing. */
router.post('/upload', function (req, routerRes) {
    try {
        qn.upImg(req, function (res) {
            if (res.status === 200) {
                routerRes.json(result(res.data, true));
            } else {
                routerRes.json(result(res.msg, false, res.status));
            }
        });
    } catch (err) {
        if (err) {
            console.log('trycatch报错====', err);
        }
    }
});

module.exports = router;
